package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.Canteen;
import com.example.mapper.CanteenMapper;
import com.example.service.CanteenService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class CanteenServiceImpl extends ServiceImpl<CanteenMapper, Canteen> implements CanteenService {
    
    @Override
    public Canteen getByUuid(String uuid) {
        LambdaQueryWrapper<Canteen> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Canteen::getUuid, uuid);
        return getOne(wrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateStatus(Long id, Integer status) {
        Canteen canteen = getById(id);
        if (canteen == null) {
            return false;
        }
        canteen.setStatus(status);
        return updateById(canteen);
    }

    @Override
    public Canteen getBySchoolId(Long schoolId) {
        LambdaQueryWrapper<Canteen> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Canteen::getSchoolId, schoolId);
        return getOne(wrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateCanteen(Canteen canteen) {
        return updateById(canteen);
    }
} 